package com.villaday.idf.adapter3;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.model3.DataEntity;
import com.villaday.idf.model3.HashStatesEntity;
import com.villaday.idf.util.PhoneUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HouseManageItemAdapter extends AbsRecyclerViewAdapter<HashStatesEntity.BodyBean.MonthsBean.DaysBean> {

    public HouseManageItemAdapter(Context context) {
        super(context, R.layout.recycle_house_manage_item);
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, HashStatesEntity.BodyBean.MonthsBean.DaysBean d, int position) {
        RelativeLayout llHmi = (RelativeLayout) holder.getView(R.id.rl_hmi);
        if (d.getText().equals("default")) {
            llHmi.setVisibility(View.INVISIBLE);
        } else {
            llHmi.setVisibility(View.VISIBLE);
            TextView tvTitle16 = (TextView) holder.getView(R.id.tv_hmi_title16);
            TextView tvTitle14 = (TextView) holder.getView(R.id.tv_hmi_title14);
            TextView tvMoney = (TextView) holder.getView(R.id.tv_hmi_money);
            TextView tvNum = (TextView) holder.getView(R.id.tv_hmi_num);

            Pattern p = Pattern.compile("[0-9]*");
            Matcher m = p.matcher(d.getText());
            if (m.matches()) {
                tvTitle16.setVisibility(View.VISIBLE);
                tvTitle14.setVisibility(View.GONE);
            } else {
                tvTitle16.setVisibility(View.GONE);
                tvTitle14.setVisibility(View.VISIBLE);
            }
            tvTitle16.setText(d.getText());
            tvTitle14.setText(d.getText());
            tvMoney.setText(Html.fromHtml(" &yen; " + d.getCostPrice()));
            tvNum.setText(d.getUsedQuantity() + "/" + d.getTotalQuantity());

            if (d.getState() == 4) {//不可选中
                llHmi.setBackgroundResource(R.color.colorWhite);
                tvTitle16.setTextColor(context.getResources().getColor(R.color.colorTextLight));
                tvTitle14.setTextColor(context.getResources().getColor(R.color.colorTextLight));
                tvMoney.setTextColor(context.getResources().getColor(R.color.colorTextLight));
                tvNum.setTextColor(context.getResources().getColor(R.color.colorTextLight));
                tvMoney.setVisibility(View.GONE);
                tvNum.setVisibility(View.GONE);
            } else {
                tvMoney.setVisibility(View.VISIBLE);
                tvNum.setVisibility(View.VISIBLE);
                if (d.isSelect()) {
                    llHmi.setBackgroundResource(R.drawable.shape_gradient_50_20_4);
                    tvTitle16.setTextColor(context.getResources().getColor(R.color.colorWhite));
                    tvTitle14.setTextColor(context.getResources().getColor(R.color.colorWhite));
                    tvMoney.setTextColor(context.getResources().getColor(R.color.colorWhite));
                    tvNum.setTextColor(context.getResources().getColor(R.color.colorWhite));
                } else {
                    if (d.getState() == -1) {//d.getState() == -1 已关房
                        llHmi.setBackgroundResource(R.color.colorWhite);
                        tvTitle16.setTextColor(context.getResources().getColor(R.color.colorTextLight));
                        tvTitle14.setTextColor(context.getResources().getColor(R.color.colorTextLight));
                        tvMoney.setTextColor(context.getResources().getColor(R.color.colorTextLight));
                        tvNum.setTextColor(context.getResources().getColor(R.color.colorTextLight));
                    } else {
                        llHmi.setBackgroundResource(R.color.colorWhite);
                        tvTitle16.setTextColor(context.getResources().getColor(R.color.colorTextBlack));
                        tvTitle14.setTextColor(context.getResources().getColor(R.color.colorTextBlack));
                        tvMoney.setTextColor(context.getResources().getColor(R.color.colorF73637));
                        tvNum.setTextColor(context.getResources().getColor(R.color.colorTextBlack));
                    }
                }
            }
        }
    }
}
